home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / graphics / 3dvect30.arj / IRQ.ASM < prev    next >
Assembly Source File  |  1993-11-18  |  6KB  |  247 lines

  1. ; irq handler for updating vector locations/angles
  2. ;
  3. ; this uses irq 8 set to the same speed as the vertical retrace so that
  4. ; an animation will remain at a smooth/constant speed regardless of the
  5. ; machine speed: eg, a 386SX33 will run an animation at the same  speed
  6. ; as a 486DX66, only the 386 will skip frames to compensate.all the irq
  7. ; really does is "inc traces_past" and this information is used to skip
  8. ; frames. if traces_past =1 is 486DX66, =4 is 386 or whatever.  you get
  9. ; the idea right?
  10. ;
  11. ; the irq can operate in real mode or pmode.  just call the appropiate
  12. ; routine.  i did this in case you want to add to  the  irq  your  own
  13. ; functions for sound or music or whatever.
  14.  
  15.         .386p
  16.         jumps
  17.  
  18.         public set_pmirq
  19.         public reset_pmirq
  20.  
  21.         public set_rmirq
  22.         public reset_rmirq
  23.  
  24.         public reset_raster_count
  25.         public time_raster
  26.  
  27.         public frametime
  28.  
  29.         public traces_past
  30.         public frame_number
  31.  
  32.         include 3d.inc
  33.         include equ.inc
  34.  
  35.         pmodeirq equ 0  ; you could also use irq 8 for either of these.
  36.         rmodeirq equ 8  ; both can run at the same time even if both=0.
  37.  
  38. code16  segment para public use16
  39.         assume cs:code16, ds:code16
  40.  
  41. ;─────────────────────────────────────────────────────────────────────────────
  42. rmirq0:                                 ; real mode IRQ0 handler
  43.         push ax ds
  44.  
  45. ; put your real mode irq code here!!!!!
  46. ;--------------------------------------
  47.  
  48.  
  49.  
  50. ;--------------------------------------
  51.  
  52. ; now my code, this is where i inc that variable
  53. ; real mode irq increments protected mode memory location
  54.  
  55.         mov ax,cs:rfs
  56.         mov ds,ax
  57.         mov si,cs:rfo
  58.  
  59.         inc word ptr [si]               ; inc traces_past
  60.         inc dword ptr [si+2]            ; inc frame_number
  61.  
  62.         pop ds
  63.         mov al,20h
  64.         out 20h,al
  65.         pop ax
  66.  
  67.         iret
  68.  
  69. rfs     dw ?
  70. rfo     dw ?
  71.  
  72. transfer_location:
  73.         mov cs:rfs,cx                   ; set protected mode location of
  74.         mov cs:rfo,dx                   ; traces_past in terms of real mode
  75.         ret
  76.  
  77. code16  ends
  78.  
  79. code32  segment para public use32
  80.         assume cs:code32, ds:code32
  81.  
  82.         include pmode.inc
  83.  
  84. ormirq0 dd ?                            ; old real mode IRQ handler seg:off
  85. opmirq0 dd ?                            ; old protected mode IRQ handler off
  86.  
  87. traces_past  dw 0                   ; contains frame speed (irq driven)
  88. frame_number dd 0                   ; number of frames total,eg 23400 = 13 mins
  89.  
  90. pmirq0:                                 ; protected mode IRQ0 handler
  91.  
  92. ; put your protected mode irq code here!!!!!
  93. ;-------------------------------------------
  94.  
  95.  
  96.  
  97. ;-------------------------------------------
  98.  
  99. ; now my code, this is where i inc that variable
  100. ; protected mode version is easy!
  101.  
  102.         inc traces_past
  103.         inc frame_number
  104.  
  105.         jmp cs:opmirq0                  ; chain to old IRQ0 redirector
  106.  
  107. set_rmirq:
  108.         mov eax,gs:[rmodeirq*4]         ; save real mode IRQ0 vector
  109.         mov ormirq0,eax
  110.  
  111.         cli                             ; set IRQ0 to inc variable
  112.  
  113.         mov word ptr gs:[rmodeirq*4],offset rmirq0  ; set real mode irq
  114.         mov word ptr gs:[(rmodeirq*4)+2],code16
  115.  
  116.         mov edx,offset traces_past      ; tell real mode irq where traces_past
  117.         add edx,_code32a                ; is in memory (pmode location)
  118.         mov al,dl
  119.         and ax,0fh
  120.         shr edx,4
  121.         mov v86r_cx,dx
  122.         mov v86r_dx,ax
  123.  
  124.         mov cx,seg transfer_location
  125.         mov dx,offset transfer_location
  126.         int 32h
  127.  
  128.         sti
  129.  
  130.         jmp new_timer
  131.  
  132. reset_rmirq:
  133.         cli
  134.  
  135.         mov eax,ormirq0                 ; restore old real mode IRQ0 vector
  136.         mov gs:[rmodeirq*4],eax
  137.  
  138.         sti
  139.  
  140.         jmp old_timer
  141.  
  142. set_pmirq:
  143.         xor bl,bl                       ; get protected mode IRQ0 redirector
  144.         call _getirqvect
  145.         mov opmirq0,edx
  146.  
  147.         cli                             ; set IRQ0 to inc variable
  148.  
  149.         mov bl,pmodeirq
  150.         mov edx,offset pmirq0
  151.         call _setirqvect                ; set protected mode irq
  152.  
  153.         sti
  154.  
  155.         jmp new_timer
  156.  
  157. reset_pmirq:
  158.         cli
  159.  
  160.         mov bl,pmodeirq
  161.         mov edx,opmirq0
  162.         call _setirqvect
  163.  
  164.         sti
  165.  
  166.         jmp old_timer
  167.  
  168. new_timer:
  169.         call time_raster
  170.  
  171.         cli
  172.         mov al,36h
  173.         out 43h,al
  174.         mov ax,frametime               ; set irq 8 time to match raster time
  175.         out 40h,al
  176.         mov al,ah
  177.         out 40h,al
  178.         sti
  179.  
  180.         ret
  181.  
  182. old_timer:                             ; reset timer for exit
  183.         cli
  184.         mov al,36h
  185.         out 43h,al
  186.  
  187.         mov ax,0
  188.         out 40h,al
  189.         out 40h,al
  190.  
  191.         sti
  192.  
  193.         ret
  194.  
  195. reset_raster_count:                    ; reset count before any animation loop
  196.         cli
  197.         mov traces_past,1
  198.         mov frame_number,0
  199.         sti
  200.         ret
  201.  
  202. frametime dw 0
  203.  
  204. time_raster:
  205.         cli
  206.         mov dx, input_1        ; input# 1 reg
  207. loop1:
  208.         in al,dx               ; wait for vsync
  209.         test al,8
  210.         jnz loop1
  211. loop2:
  212.         in al,dx
  213.         test al,8
  214.         jz loop2
  215.  
  216.         mov al,36h             ; reset timer
  217.         out 43h,al
  218.         mov al,0
  219.         out 40h,al
  220.         mov al,0
  221.         out 40h,al
  222. loop3:
  223.         in al,dx               ; wait for vsync
  224.         test al,8
  225.         jnz loop3
  226. loop4:
  227.         in al,dx
  228.         test al,8
  229.         jz loop4
  230.  
  231.         xor al,al              ; this calculation code courtesy future_crew
  232.         out 43h,al             ; from mental.exe
  233.         in al,40h
  234.         mov ah,al
  235.         in al,40h
  236.         xchg al,ah
  237.         neg ax
  238.         shr ax,1
  239.         mov frametime,ax
  240.  
  241.         sti
  242.         ret
  243.  
  244. code32  ends
  245.         end
  246.  
  247.